﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ComputerBeacon.Csv;
using ComputerBeacon.Serialization;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            Deserialize();
            Serialize();
            Table();
            EscapedCharacters();

            Console.ReadLine();
        }

        static void Deserialize() {
            var s = "Year,Make,Model,Length\r\n1997,Ford,E350,2.34\r\n2000,Mercury,Cougar,2.38";
            var cars = Serialization.Deserialize<Car>(s);
            foreach (var c in cars) Console.WriteLine(c);
        }

        static void Serialize() {
            var cars = new Car[]{
                new Car{ Year=1997, Make="Ford", Model = "E350", Length=2.34},
                new Car{ Year=2000, Make = "Mercury", Model = "Cougar", Length=2.38}
            };
            Console.WriteLine(Serialization.Serialize(cars));
        }

        static void Table() {
            var table = new CsvTable("Year,Make,Model\r\n1997,Ford,E350\r\n2000,Mercury,Cougar", true);
            Console.WriteLine(table[1, "Make"]);
        }

        static void EscapedCharacters() {
            var messages = new[] { new Message { Sender = "user", Text = "Hey, how are you?" } };
            var s = Serialization.Serialize(messages);
            var table = new CsvTable(s, true);
            Console.WriteLine(table[0, "Text"]);
        }


        class Message {
            public string Sender;
            public string Text;
        }

        class Car {
            public int Year;
            public string Make;
            public string Model;
            public double Length;
            public override string ToString() {
                return "Year=" + Year + ",Make=" + Make + ",Model=" + Model + ",Length=" + Length;
            }
        }
    }
}
